package com.uchedao.seller.ui.car.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.uchedao.seller.R;
import com.uchedao.seller.http.entity.CarBiddingBean;
import com.uchedao.seller.ui.adapter.CommonAdapter;
import com.uchedao.seller.ui.adapter.ViewHolder;
import com.uchedao.seller.ui.car.manage.ViewBidActivity;
import com.uchedao.seller.util.Arith;
import com.uchedao.seller.widget.dialog.CutPriceDialog;

import java.util.List;

/**
 * Created by hang on 2015/10/23.
 */
public class CarBidEndAdapter extends CommonAdapter<CarBiddingBean> {

    public CarBidEndAdapter(Context context, List<CarBiddingBean> data) {
        super(context, data, R.layout.item_car_bid_end);
    }

    @Override
    public void conver(ViewHolder holder, final CarBiddingBean item, int position) {
        holder.getView(R.id.btnPromote).setVisibility(View.GONE);
        holder.getView(R.id.btnSubmit).setVisibility(View.GONE);

        Button btnDelete = holder.getView(R.id.btnDelete);
        Button btnUpdate = holder.getView(R.id.btnUpdate);
        Button btnCutPrice = holder.getView(R.id.btnCutPrice);
        Button btnViewPrice = holder.getView(R.id.btnViewPrice);

        btnViewPrice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent it = new Intent(mContext, ViewBidActivity.class);
                it.putExtra("data", item);
                it.putExtra("click", false);
                mContext.startActivity(it);
            }
        });
        btnCutPrice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CutPriceDialog dlg = new CutPriceDialog(mContext);
                dlg.setCarBiddingBean(item);
                dlg.show();
            }
        });

        TextView tvTag = holder.getView(R.id.tvCarItemTag);
        LinearLayout llContent = holder.getView(R.id.llCarItemContent);
        LinearLayout llBtns = holder.getView(R.id.llCarItemBtns);

        if(position == 0) {
            tvTag.setVisibility(View.VISIBLE);
            llContent.setVisibility(View.GONE);
            llBtns.setVisibility(View.GONE);
            tvTag.setText("全部竞价结束车辆");
        } else {
            tvTag.setVisibility(View.GONE);
            llContent.setVisibility(View.VISIBLE);
            llBtns.setVisibility(View.VISIBLE);
            btnViewPrice.setVisibility(item.getBid_num()>0? View.VISIBLE:View.GONE);
            initContent(holder, item, position);
        }
    }

    /**
     * 填充车辆内容
     */
    public void initContent(ViewHolder holder, CarBiddingBean item, int position) {
        holder.setImageByURL(R.id.ivCarItemPic, item.getCover_photo());
        holder.setText(R.id.tvCarItemTitle, item.getTitle());
        holder.setText(R.id.tvCarItemKmDate, Arith.div(item.getKilometer(),10000)+"万公里 "+item.getCard_time());
        holder.setText(R.id.tvCartItemReservePrice, Arith.div(item.getReserve_price(),10000)+"");
        holder.setText(R.id.tvCarItemMaxPrice, item.getBid_num()>0? Arith.div(item.getMax_bid_price(),10000)+"":"--");
        holder.setText(R.id.tvCarItemEndTime, item.getEnd_time()+"结束");
        holder.setText(R.id.tvCarItemLookNum, item.getLook_num()+"人围观");
        holder.setText(R.id.tvCarItemBidNum, item.getBid_num()+"人出价");
    }
}
